<template>
  <div class="login">
    <div class="loginToHome">
      <el-form
        ref="form"
        :model="form"
        :rules="ruleForm"
        status-icon
        label-width="80px"
        class="loginForm"
      >
        <h2 style="margin-bottom: 6px">管理员登陆</h2>
        <el-form-item label="账户" prop="admin_name">
          <el-input
            maxlength="10"
            minlength="4"
            type="text"
            v-model="form.admin_name"
            auto-complete="off"
            placeholder="请输入用户名"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="admin_pwd">
          <el-input
            maxlength="10"
            minlength="6"
            type="password"
            v-model="form.admin_pwd"
            auto-complete="off"
            placeholder="请输入密码"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button class="homeBut" type="info" plain @click="submit"
            >登录</el-button
          >
          <el-button class="loginBut" type="info" plain @click="resetForm()"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      form: {
        admin_name: "",
        admin_pwd: "",
      },
      ruleForm: {
        admin_name: [
          { required: true, message: "请输入账号", trigger: "blur" },
        ],
        admin_pwd: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  methods: {
    submit() {
      const url = `/admin/${this.form.admin_name}/${this.form.admin_pwd}`;
      this.axios.get(url).then((res) => {
        if (res.data.code == 200) {
          this.$router.push("/backstage");
          sessionStorage.setItem('admin',this.form.admin_name)
        } else {
          alert("登录失败");
        }
      });
    },
    resetForm() {
      this.$refs.form.resetFields();
    },
  },
};
</script>
<style>
.login {
  height: 100vh;
  width: 100vw;
  background-image: url(../assets/veer2.png);
  background-repeat: no-repeat;
  background-size: cover;
}
.loginToHome {
  position: absolute;
  left: 50%;
  right: 0;
  top: 0;
  bottom: 0;
  margin: auto;
  width: 400px;
  height: 260px;
  -webkit-border-radius: 5px;
  border-radius: 5px;
  background: #fff;
  border: 1px solid #dcdfe6;
}
.loginForm {
  text-align: center;
  padding-top: 15px;
  padding-right: 30px;
  top: 10px;
}
.homeBut {
  position: absolute;
  left: 0px;
}
.loginBut {
  position: absolute;
  right: 0px;
}
</style>
 
